import Base64 from 'base-64'
import CryptoJS from 'crypto-js/crypto-js'
function makeToken(path,host,method,query,header){
	 let accesskey='V-AqkiRIYIf1-T4nOtM07nBgGS-ytRu9M-2tNagS'
	//let accesskey='MY_ACCESS_KEY'
	 let secretkey='fWtYj2MkKVVpBGcKs0WrYbvs-QYP7oLRrz72JFLM';
	//let secretkey='MY_SECRET_KEY'
	let signString=method+' '+path
	if(query){
		signString=signString+'?'+query;
	}
	
	
	signString=signString+'\n'+'Host: '+host;
	if(header){
		signString=signString+'\n'+'Content-Type: '+header;
	}
	signString=signString+'\n'+'\n';
	//console.log(signString)
	let sign=CryptoJS.HmacSHA1(signString, secretkey);
	//console.log(CryptoJS.enc.Hex.stringify(sign))
	let encodeString=CryptoJS.enc.Base64url.stringify(sign);
	return accesskey+':'+encodeString;
}
function arrtovex(arr){
	var str="";
	for(var i=0;i<arr.length;i++){
		var tmp=arr[i].toString(16);
		if(tmp.length==1){
			tmp='0'+tmp;
		}
		str+=tmp;
	}
	return str;
}
export default {makeToken}